package com.example.easyexcel.dao;

import com.example.easyexcel.dto.AssetBasicInfoDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AssetBasicInfoMapper {

    /**
     * 插入资产基本信息
     */
    @Insert("INSERT INTO asset_basic_info (" +
            "asset_no, asset_name, asset_type_id, data_asset_sc, " +
            "business_theme_domain_tc, create_time, update_time" +
            ") VALUES (" +
            "#{assetNo}, #{assetName}, #{assetTypeId}, #{dataAssetSc}, " +
            "#{businessThemeDomainTc}, #{createTime}, #{updateTime}" +
            ")")
    int insert(AssetBasicInfoDTO assetBasicInfo);

    /**
     * 批量插入资产基本信息
     */
    @Insert("<script>" +
            "INSERT INTO asset_basic_info (" +
            "asset_no, asset_name, asset_type_id, data_asset_sc, " +
            "business_theme_domain_tc, create_time, update_time" +
            ") VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(" +
            "#{item.assetNo}, #{item.assetName}, #{item.assetTypeId}, #{item.dataAssetSc}, " +
            "#{item.businessThemeDomainTc}, #{item.createTime}, #{item.updateTime}" +
            ")" +
            "</foreach>" +
            "</script>")
    int insertBatch(@Param("list") List<AssetBasicInfoDTO> list);

    /**
     * 检查资产编号是否已存在
     */
    @Select("SELECT COUNT(1) FROM asset_basic_info WHERE asset_no = #{assetNo}")
    int existsByAssetNo(@Param("assetNo") String assetNo);
}
